#!/usr/bin/env python
# -*- coding: utf-8 -*-
'''
@Author   : 李吉凯
@Email    : lijikai1206@163.com
@Time     : 2021/7/11 18:37
@File     : BaseFeishu.py
'''
import requests

from service.FeishuApi.utils.dataJM import encode_base64


class BaseFeishu:
    def __init__(self):
        self.kl_req = requests.Session()
        self.token: str = self.get_token()
        self.res02: str = self.get_service_token()

    def get_token(self):
        url = 'https://open.feishu.cn/open-apis/auth/v3/app_access_token/internal/'
        header = {
            'application': 'json',
            'charset':  'utf-8'
        }
        data = {
            "app_id": "cli_a0602fc96bf8d00b",
            "app_secret": "WBVtmEepFbPKoS0GSwDH5feinQunoDts"
        }
        r = requests.post(url, json=data)
        print('res:', r)
        print('res_text', r.json())
        print('token:', r.json()['app_access_token'])
        return r.json()['app_access_token']

    def get_service_token(self):
        helpdesk_id = "6983817089911898115"
        helpdesk_token = "ht-6c8159d8-3ffa-77ff-97d1-10a660a67704"
        s01 = helpdesk_id + ":" + helpdesk_token
        self.res02 = encode_base64(s01)
        print('service token:', self.res02)
        return self.res02

    def send(self, *args, **kwargs):
        res = self.kl_req.post(*args, **kwargs)
        return res